//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.ruoyi.socket.util.midr;


import java.text.SimpleDateFormat;
import java.util.Date;

import com.ruoyi.socket.util.midr.hl7.Field;
import com.ruoyi.socket.util.midr.hl7.Message;
import com.ruoyi.socket.util.midr.hl7.Segment;
import org.xml.sax.Attributes;
import org.xml.sax.helpers.DefaultHandler;

class MindrayConfigHandler extends DefaultHandler {
    Message a = new Message();
    private Segment b = null;
    private Field c = null;
    private String d = null;
    private String[] e = null;
    private int f = -1;
    private String g = null;
    private boolean h = false;
    private String i;
    private Message j = null;
    private int k;
    private String[] l;

    public MindrayConfigHandler(String var1) {
        this.e = var1.split("<::>");
        String[] var2 = this.e[0].split("\\|");
        this.g = var2[8].trim().substring(0, 7);
    }

    private MindrayConfigHandler(int var1) {
    }

    private MindrayConfigHandler(Message var1, String var2) {
        this.g = var2;
        this.j = var1;
    }

    public void startDocument() {
    }

    public void startElement(String var1, String var2, String var3, Attributes var4) {
        if ("type".equals(var3)) {
            if (var4.getValue("name").equalsIgnoreCase(this.g)) {
                this.a.type = var4.getValue("name");
                this.a.description = var4.getValue("description");
                this.a.initiator = var4.getValue("initiator");
                this.a.replymessage = var4.getValue("replymessage");
                this.a.responseto = var4.getValue("responseto");
                this.a.follow = var4.getValue("follow");
                this.h = true;
                return;
            }
        } else if ("segment".equals(var3)) {
            if (this.h) {
                this.b = new Segment();
                this.b.id = var4.getValue("id");
                this.b.name = var4.getValue("name");
                this.b.description = var4.getValue("description");
                this.b.fieldlength = Integer.parseInt(var4.getValue("fieldlength"));
                this.b.position = Integer.parseInt(var4.getValue("position"));
                ++this.f;
                return;
            }
        } else if ("field".equals(var3) && this.h) {
            this.c = new Field();
        }

    }

    public void endElement(String var1, String var2, String var3) {
        if ("type".equals(var3)) {
            if (this.h) {
                this.h = false;
                return;
            }
        } else if ("segment".equals(var3)) {
            if (this.h) {
                this.a.Segments.add(this.b);
                this.b = null;
                return;
            }
        } else if ("field".equals(var3)) {
            if (this.h) {
                if (this.b.name.equalsIgnoreCase("MSH")) {
                    this.c.realValue = this.a(this.c.position - 1);
                } else {
                    this.c.realValue = this.a(this.c.position);
                }

                this.b.Fields.add(this.c);
                this.c = null;
                return;
            }
        } else if ("name".equals(var3)) {
            if (this.h) {
                this.c.name = this.d;
                return;
            }
        } else if ("position".equals(var3)) {
            if (this.h) {
                this.c.position = Integer.parseInt(this.d);
                return;
            }
        } else if ("datatype".equals(var3)) {
            if (this.h) {
                this.c.datatype = this.d;
                return;
            }
        } else if ("default".equals(var3)) {
            if (this.h) {
                this.c.defaultvalue = this.d;
                return;
            }
        } else if ("format".equals(var3) && this.h) {
            this.c.format = this.d;
        }

    }

    public void characters(char[] var1, int var2, int var3) {
        this.d = String.copyValueOf(var1, var2, var3).trim();
    }

    private String a(int var1) {
        try {
            String[] var10;
            if (this.j == null) {
                var10 = this.e[this.f].split("\\|");
                return var1 >= var10.length ? null : var10[var1].trim();
            } else if (this.c.defaultvalue == null) {
                return null;
            } else if (this.c.defaultvalue.contains("[") && this.c.defaultvalue.contains("]") && this.c.defaultvalue.contains("-")) {
                String var9 = this.c.defaultvalue;
                MindrayConfigHandler var8 = this;
                String var11 = "";
                var10 = var9.split("\\-|\\[|\\]");
                if (this.j.type.equalsIgnoreCase(var10[0])) {
                    for(int var4 = 0; var4 < var8.j.Segments.size(); ++var4) {
                        if (((Segment)var8.j.Segments.get(var4)).name.equalsIgnoreCase(var10[1])) {
                            for(int var5 = 0; var5 < ((Segment)var8.j.Segments.get(var4)).Fields.size(); ++var5) {
                                if (((Field)((Segment)var8.j.Segments.get(var4)).Fields.get(var5)).position == Integer.parseInt(var10[2])) {
                                    var11 = ((Field)((Segment)var8.j.Segments.get(var4)).Fields.get(var5)).realValue;
                                    return var11;
                                }
                            }

                            return var11;
                        }
                    }
                }

                return var11;
            } else if (this.c.defaultvalue.contains("sysdatetime")) {
                String var7 = this.c.format;
                SimpleDateFormat var3 = new SimpleDateFormat(var7);
                Date var2 = new Date();
                return var3.format(var2);
            } else {
                return this.c.defaultvalue;
            }
        } catch (ArrayIndexOutOfBoundsException var6) {
            return null;
        }
    }

    private String a(String var1) {
        String var2 = "";
        String[] var5 = var1.split("\\-|\\[|\\]");
        if (this.j.type.equalsIgnoreCase(var5[0])) {
            for(int var3 = 0; var3 < this.j.Segments.size(); ++var3) {
                if (((Segment)this.j.Segments.get(var3)).name.equalsIgnoreCase(var5[1])) {
                    for(int var4 = 0; var4 < ((Segment)this.j.Segments.get(var3)).Fields.size(); ++var4) {
                        if (((Field)((Segment)this.j.Segments.get(var3)).Fields.get(var4)).position == Integer.parseInt(var5[2])) {
                            var2 = ((Field)((Segment)this.j.Segments.get(var3)).Fields.get(var4)).realValue;
                            return var2;
                        }
                    }

                    return var2;
                }
            }
        }

        return var2;
    }

    private static String b(String var0) {
        SimpleDateFormat var2 = new SimpleDateFormat(var0);
        Date var1 = new Date();
        return var2.format(var1);
    }
}
